package com.crm.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.crm.business.domain.TbBusiness;

import com.crm.business.domain.TbBusinessRecord;
import com.crm.business.domain.vo.TbBusinessVo;
import com.crm.common.domain.vo.IndexStatisticsVo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface BusinessMapper extends BaseMapper<TbBusiness> {

    //查询所有商机
    List<TbBusinessVo> selecBusinessList(TbBusinessVo tbBusinessVo);

    //查询商机池
    List<TbBusiness> selecBusinessPool(TbBusiness tbBusiness);

    //根据id查询商机
    TbBusiness selectBusinessById(Long id);

    //新增商机
    void insertTbBusiness(TbBusiness tbBusiness);

    //商机分配
    void update(TbBusiness build);

    //查询商机记录
    @Select("select * from tb_business_record where business_id = #{id}")
    List<TbBusinessRecord> selectRecordList(Long id);

    //新增商机跟进记录
    void insertRecord(TbBusinessRecord tbBusinessRecord);

    //修改商机跟进记录
    int updateBusiness(TbBusiness tbBusiness);

    //删除商机跟进记录
    @Delete("delete from tb_business_record where business_id = #{id}")
    void deleteRecord(Long id);

    // 踢入公海池,清空跟进信息,
    int updateBusinessRecord(TbBusiness tbBusiness);


    int countAllBusiness(@Param("beginCreateTime") String beginCreateTime,
                         @Param("endCreateTime") String endCreateTime);

    List<Map<String,Object>> countAllContractByUser(@Param("indexVo") IndexStatisticsVo vo);

    Integer businessNumsFromClue(@Param("beginCreateTime") String beginCreateTime,
                                 @Param("endCreateTime") String endCreateTime);


    @Select("select count(*) from tb_business where owner = #{userName}")
    Integer countBusinessByUser(String userName);

    @Update("update tb_business set owner = #{transferUserName} where owner = #{userName}")
    void transfer(String userName, String transferUserName);
}


